<?php defined('InNcPHP') or exit('Access Invalid!');?>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<link rel="stylesheet"  type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css">
<style>
    .show { display: block; }
    .hide { display: none; }
    .code_img{display: none;}
</style>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['bargain_index_ticket'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  操作提示  -->
    <table class="table tb-type2" id="prompt">
        <tbody>
        <tr class="space odd">
            <th colspan="12">
                <div class="title">
                    <h5><?php echo $lang['nc_prompts']; ?></h5>
                    <span class="arrow"></span>
                </div>
            </th>
        </tr>
        <tr>
            <td>
                <ul>
                    <li>此处信息请按照规范填写,所填信息会提交给第三方支付平台,银行需要审核完成之后，所属商户才可以进行收款功能,请尽可能的保证所填信息准确！</li>
                </ul>
            </td>
            <td>
            </td>
        </tr>
        </tbody>
    </table>
    <form id="merchant_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2 nobdb">
            <tbody>
            <!-- 店铺名称 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_shop_name'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="mc_shop_name" class="txt" value="<?php echo $output['merchant_info']['mc_shop_name']; ?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_title_notice'];?></td>
            </tr>

            <!-- 商家类型 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_cate'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select id="cate1" name="cate1" class="class-select">
                        <option value="">选择分类</option>
                        <?php if (is_array($output['cate'])): ?>
                            <?php foreach ($output['cate'] as $k => $v): ?>
                                <option value="<?php echo $v['tc_id']; ?>" <?php echo $output['merchant_info']['mc_cate'] == $v['tc_id'] ? 'selected' : ''; ?>><?php echo $v['tc_name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 店铺联系人 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_name'];?>:</label>
                </td>
            </tr>

            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="mc_name" class="txt" value="<?php echo $output['merchant_info']['mc_name']; ?>"></td>
                <td class="vatop tips"><?php echo $lang['bargain_add_show_price_notice'];?></td>
            </tr>

            <!-- 联系人手机 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_phone'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="mc_phone" id="mc_phone" class="txt" value="<?php echo $output['merchant_info']['mc_phone']; ?>"></td>
                <td class="vatop tips " style="color:red;font-size: 15px;">PS:请保证该手机号是唯一的，请仔细核对</td>
            </tr>

            <!-- 商家营业执照 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_lic'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['merchant_info']['mc_lic_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="mc_lic_img" type="file" class="type-file-file" id="image" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo '商户的营业执照';?></td>
            </tr>

            <!-- 身份证正面照片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_idcard'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['merchant_info']['mc_idcard_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield1' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="mc_idcard_img" type="file" class="type-file-file" id="image1" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo  '商户联系的人身份证正面照';?></td>
            </tr>

            <!-- 身份证反面照片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_idcardb'];?>:</label>
                </td>
            </tr>

            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['merchant_info']['mc_idcardb_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield2' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="mc_idcardb_img" type="file" class="type-file-file" id="image2" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo '商户联系的人身份证反面照';?></td>
            </tr>
            <!-- 商家封面图 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">商家封面图:</label>
                </td>
            </tr>

            <tr class="noborder">
                <td class="vatop rowform"><span class="type-file-show">
                        <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['merchant_info']['mc_cover_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    </span> <span class="type-file-box">
                        <input type='text' name='textfield3' id='textfield3' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="mc_cover_img" type="file" class="type-file-file" id="image3" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo '商户的封面图';?></td>
            </tr>

            <!-- 商家提现费率-->
            <?php if($output['admin_info']['merchant_id']==0) :?>
                <tr class="noborder">
                    <td colspan="2" class="required">
                        <label class="validation">商家提现费率:</label>
                    </td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><input type="text" name="pd_tariff" class="txt" <?php if($output['admin_info']['merchant_id']>0){ ?>  readonly="true"  <?php } ?>  value="<?php echo $output['merchant_info']['pd_tariff']; ?>"><span style="color:red">%</span></td>
                    <td class="vatop tips" style="color:red">(平台填写,此处填写的值为百分比例如1为百分之一的手续费,以此类推 为0或为空 代表不收取手续费)</td>
                </tr>
            <?php endif; ?>

            <tr>
                <td colspan="2" class="required">
                    <label class="validation">地址: </label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select id="store_areaId_01" name="province_id" class="class-select">
                        <option value="">省份</option>
                        <?php if (is_array($output['provinces'])): ?>
                            <?php foreach ($output['provinces'] as $k => $v): ?>
                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['merchant_info']['province_id'] == $v['area_id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                    <select id="store_areaId_02" name="city_id" class="class-select">
                        <option value="">城市</option>
                        <?php if (is_array($output['citys'])): ?>
                            <?php foreach ($output['citys'] as $k => $v): ?>
                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['merchant_info']['city_id'] == $v['area_id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                    <select id="store_areaId_03" name="area_id" class="class-select">
                        <option value="">区/县</option>
                        <?php if (is_array($output['areas'])): ?>
                            <?php foreach ($output['areas'] as $k => $v): ?>
                                <option value="<?php echo $v['area_id']; ?>" <?php echo $output['merchant_info']['area_id'] == $v['area_id'] ? 'selected' : ''; ?>><?php echo $v['name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>

            <!-- 商家详细地址-->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_address'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="address" class="txt" value="<?php echo $output['merchant_info']['address']; ?>"></td>
                <td class="vatop tips"><?php echo '填写商家所在的详细地址，例如‘思明区xxxxxxxx’';?></td>
            </tr>

            <!-- 商家服务电话-->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_service_phone'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="service_phone" class="txt" value="<?php echo $output['merchant_info']['service_phone']; ?>"></td>
                <td class="vatop tips"><?php echo '此处请填写商家的座机，若无座机请填写商家联系的人手机号';?></td>
            </tr>
            <!-- 商家身份证号码-->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['merchant_id_card_no'];?>:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="id_card_no" class="txt" value="<?php echo $output['merchant_info']['id_card_no']; ?>"></td>
                <td class="vatop tips"><?php echo '商户联系人的身份证号码';?></td>
            </tr>
            <!-- 酒店介绍 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">商家介绍:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td colspan="2" class="vatop rowform">
                    <textarea id="content" name="content" style="width:70%;height: 400px;"><?php echo $output['merchant_info']['mc_content'] ?></textarea>
                </td>
            </tr>
            <!-- 提交 -->
            <tr class="tfoot">
                <td colspan="2" >
                    <a href="JavaScript:void(0);" class="btn" id="submitBtn">
                        <span><?php echo $lang['nc_submit'];?></span>
                    </a>
                </td>
            </tr>
            </tfoot>

        </table>
    </form>
</div>
<script type="text/javascript" SRC="./resource/kindeditor/kindeditor-min.js"></script>
<script>

    $('#bank_no').bind('input propertychange', function() {
        $("#bank_info_name").empty();
        var name = $(this).val();
        $.ajax({
            type:"post",
            data:{name:name},
            url:'index.php?act=member&op=ajax_bank_name',
            dataType:'json',
            success:function(json){
                if(json.result == 1){
                    //$("#bank_info_name").show();
                    for (var i =0; i<json.data.length; i++){
                        var html = "";
                        html += "<option>"+json.data[i].bank_name+"</option>";
                        $("#bank_info_name").append(html);
                    }
                    $("#bank_info_name").show();
                }else{
                    $("#bank_info_name").empty();
                    $("#bank_info_name").hide();
                }
            }
        })
    });
    $("#bank_info_name").change(function(){
        $("#bank_no").val($(this).find("option:selected").text());
        $("#bank_info_name").hide();
    });
    /* $("#bank_no").change(function(){
     var name = $(this).val();
     alert(name);
     $.ajax({
     type:'post'
     })
     })*/
    $("#submitBtn").click(function(){
        if(validform().form()){
            $("#merchant_form").submit();
        }else{}
    });
    //图片文件选择
    $("#image").change(function(){
        $("#textfield").val($(this).val());
    });
    //图片文件选择
    $("#image1").change(function(){
        $("#textfield1").val($(this).val());
    });
    //图片文件选择
    $("#image2").change(function(){
        $("#textfield2").val($(this).val());
    });
    $("#image3").change(function(){
        $('#textfield3').val($(this).val());
    })
    //实例化富文本编辑器
    KindEditor.ready(function(K){
        K.create('textarea[name="content"]', {
            themeType: 'simple',
            resizeType: 1,
            uploadJson: './resource/kindeditor/php/upload_json.php',
            fileManagerJson: './resource/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function(){this.sync();}
        });

    });
    //选择省份
    $("#store_areaId_01").change(function(){

        var _areaID = $(this).val();
        _this = $("#store_areaId_01");
        if(_areaID){
            $.getJSON("./index.php?act=common&op=getAreaChild&parent_id=" + _areaID, function(data){
                $obj = $("#store_areaId_02");
                $obj.empty();
                $obj.append('<option value="">城市</option>');
                $obj.nextAll("select").empty();
                $obj.nextAll("select").append('<option value="">区/县</option>');
                $.each(data, function(i,item){
                    $obj.append('<option value="'+item.area_id+'">'+item.name+'</option>');
                });
            });
        }else{
            _this.nextAll("select").empty();
            _this.next("select").append('<option value="">城市</option>');
            _this.next("select").next('select').append('<option value="">区/县</option>');
        }
    });
    //选择城市
    $("#store_areaId_02").change(function(){
        var _areaID = $(this).val();
        _this = $("#store_areaId_2");
        if(_areaID){
            $.getJSON("index.php?act=common&op=getAreaChild&parent_id=" + _areaID, function(data){
                $obj = $("#store_areaId_03");
                $obj.empty();
                $obj.append('<option value="">区/县</option>');
                $.each(data, function(i,item){
                    $obj.append('<option value="'+item.area_id+'">'+item.name+'</option>');
                });
            });
        }else{
            _this.nextAll("select").empty();
            _this.next("select").append('<option value="">区/县</option>');
        }
    });
    //选择区/县
    $("#store_areaId_03").change(function(){
        var _areaID = $(this).val();
        if(_areaID){
            var area_p = $("#store_areaId_01").find("option:selected").text();
            var area_c = $("#store_areaId_02").find("option:selected").text();
            var area_a = $("#store_areaId_03").find("option:selected").text();
        }
    });

    //表单验证
    function validform(){
        return  $('#merchant_form').validate({
            errorPlacement: function(error, element){
                if (element.attr('type') === 'file') {
                    error.appendTo(element.parent().parent().parent().prev().find('td:first'));
                } else {
                    error.appendTo(element.parent().parent().prev().find('td:first'));
                }
            },
            rules:{
                mc_shop_name:'required',
                mch_shortname:'required',
                mc_name:'required',
                mc_phone:{required: true,
                    minlength:11,
                    maxlength:11,
                    digits:true,
                    remote:{
                        url:'index.php?act=merchant&op=check_mobile',
                        type:'get',
                        data:{
                            mc_phone : function(){
                                return $('#mc_phone').val();
                            }
                        }
                    }
                },
                email:'required',
                province:'required',
                city:'required',
                address:'required',
                district:'required',
                balance_name:'required',
                bank_no:{
                    required:true,
                    remote:{
                        url :'index.php?act=member&op=ajax',
                        type:'get',
                        data:{
                            bank_no : function(){
                                return $('#bank_no').val();
                            }
                        }
                    }
                },
                three_class:'required',
                id_card_no:{required:true,
                    minlength:18,
                    maxlength:18,
                },
                payment_type3:{required: true,
                    number: true,
                    min: 10,
                    max: 9999999
                },
                payment_type8:{required: true,
                    number: true,
                    min: 10,
                    max: 9999999
                },
                payment_type7:{
                    required: true,
                    number: true,
                    min: 10,
                    max: 9999999
                },
                service_phone:'required',
                license_num:'required',
                license_start_date:'required',
                /* license_end_date:'required',*/
                license_scope:'required',
                balance_account:'required',
                balance_type:'required',
                cate1:'required',
                province_id: 'required',
                city_id: 'required',
                area_id: 'required',
                mc_lic_img:'required',
                mc_idcard_img:'required',
                mc_idcardb_img:'required',
                mc_cover_img:'required',

            },
            messages:{
                mc_shop_name:'店铺名称不能为空',
                mch_shortname:'商户简称不能为空',
                mc_name:'店铺联系人不能为空',
                mc_phone:{
                    required: '请输入正确的手机号',
                    remote :'该手机号已经注册过商家,请重新核对',
                },
                email:'商户邮箱不能为空',
                province:'请输入商家所在省份',
                city:'请输入商家所在城市',
                district:'请输入商家所在区县',
                address:'请输入商家详细地址',
                balance_name:'请输入结算银行卡开户人姓名',
                bank_no:{
                    required : '结算支行名称不能为空',
                    remote	 :'支行未匹配到请仔细核对',
                },
                three_class:'商家所属行业请选择完整',
                id_card_no:'请输入正确身份证号码',
                payment_type3:'微信公众账号支付费率不能为空',
                payment_type8:'微信支付宝刷卡支付费率不能为空',
                payment_type7:'支付宝扫码支付费率不能为空',
                license_num:'营业执照注册号不能为空',
                license_start_date:'营业执照开始时间不能为空',
                /*license_end_date:'营业执照结束时间不能为空',*/
                license_scope:'营业执照经营范围不能为空',
                service_phone:'商家号码不能为空',
                balance_account:'商家结算银行卡不能为空,请仔细核对填写',
                balance_type:'结算类型为必选',
                cate1:'商家类型不能为空',
                province_id:'请选择省份',
                city_id:'请选择市区',
                area_id:'请选择地区',
                mc_lic_img:'商户营业执照不能为空',
                mc_idcard_img:'商户身份证正面照不能为空',
                mc_idcardb_img:'商户身份证反面照不能为空',
                mc_cover_img:'商户封面图不能为空',
            }


        })
    }

</script>
